package com.jason.wsserver.config;



import com.jason.wsserver.server.EchoWebSocketHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 1. 新建一个你的消息处理器实例
        WebSocketHandler handler = new EchoWebSocketHandler();
        // 2. 把这个 handler 注册到 “/ws” 这个端点上
        registry.addHandler(handler, "/ws")
                // 3. 允许所有来源的跨域访问（只是测试环境用，生产建议指定白名单）
                .setAllowedOrigins("*");
    }
}
